package main

import (
	"fmt"
	"log"
	"net/http"
	"runtime"
)

func foo(w http.ResponseWriter, r *http.Request) {
	buf := make([]byte, r.ContentLength)
	r.Body.Read(buf)
	fmt.Println(6666, string(buf))
	w.Write([]byte("hi! babe~"))
}

func echo(w http.ResponseWriter, r *http.Request) {
	s := fmt.Sprintf("gorotines count: %d", runtime.NumGoroutine())
	w.Write([]byte(s))
}

func main() {
	mux := http.NewServeMux()

	mux.HandleFunc("/foo", foo)
	mux.HandleFunc("/echo/goroutines", echo)

	log.Println("Listening...")
	if err := http.ListenAndServe(":30000", mux); err != nil {
		fmt.Println(err)
	}
}
